package com.freeman.cement.controller;

import com.freeman.cement.annotation.NeedRole;
import com.freeman.cement.entity.EventType;
import com.freeman.cement.entity.ResponseResult;
import com.freeman.cement.service.EventTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用于事件类型增删改查
 */
@RestController
@RequestMapping("/eventtype")
@CrossOrigin    //允许跨域访问
public class EventTypeController {

    @Resource
    private EventTypeService service;

    //region 202211

    /**
     * 取得全部事件类型列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectAllEventType", method = RequestMethod.POST)
    public ResponseResult selectAllEventType(@RequestParam int pageNo, @RequestParam  int pageSize) {
        return service.selectAllEventType(pageNo, pageSize);
    }

    /**
     * 通过关键字检索事件类型，关键字类型名称和类型数字码
     * @param keyword 类型名称和类型码
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectEventTypeByKeyword", method = RequestMethod.POST)
    public ResponseResult selectEventTypeByKeyword(String keyword, @RequestParam int pageNo, @RequestParam int pageSize){
        return service.selectEventTypeByKeyword(keyword, pageNo, pageSize);
    }

    /**
     * 新增事件类型
     * @param eventType
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/addEventType", method = RequestMethod.POST)
    public ResponseResult addEventType(EventType eventType) {
        return service.addEventType(eventType);
    }

    /**
     * 删除事件类型
     * @param id
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/deleteEventType", method = RequestMethod.POST)
    public ResponseResult deleteEventType(@RequestParam int id) {
        return service.deleteEventType(id);
    }

    /**
     * 更新事件类型
     * @param eventType
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/updateEventType", method = RequestMethod.POST)
    public ResponseResult updateEventType(EventType eventType) {
        return service.updateEventType(eventType);
    }

    //endregion




}
